package thirdwork.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import thirdwork.dao.EmployeeDao;
import thirdwork.dao.impl.EmployeeImpl;
import thirdwork.domain.Employee;

/**
 * Servlet implementation class AddEmployee
 */
@WebServlet("/AddEmployee")
public class AddEmployee extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		resp.setCharacterEncoding("UTF-8");
		Employee e = new Employee();
		e.setName(req.getParameter("empname"));
		e.setSex(req.getParameter("empsex"));
		e.setAge(Integer.parseInt(req.getParameter("empage")));
		e.setDepartment(req.getParameter("empdep"));
		e.setType(req.getParameter("emptype"));
		e.setYear(Integer.parseInt(req.getParameter("empyear")));
		EmployeeDao empdao = new EmployeeImpl();
		int a = empdao.insertEmp(e);
		System.out.println("插入了" + a + "个人");
		resp.sendRedirect(req.getContextPath() + "/ShowEmployee");
	}
}
